﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using System.IO;
using log4net.Config;

namespace Convert
{
    public class Logger
    {
        private static readonly ILog log;
        private static readonly ILog drugMatchingLog;

        static Logger()
        {
            try
            {
                log = LogManager.GetLogger("GeneralLogger");
                drugMatchingLog = LogManager.GetLogger("DrugMatchingLogger");

                //initialise and configure the logger
                string dir = Directory.GetCurrentDirectory();
                XmlConfigurator.Configure(new System.IO.FileInfo(".\\config\\log4net.config"));
            }
            catch (Exception)
            {
                //MessageBox.Show("Error setting up Logger");
            }
        }

        public static void LogDrugMatchMessage(String message)
        {
            drugMatchingLog.Debug(message);
        }

        public static void Debug(String message)
        {
            log.Debug(message);
        }

        public static void Info(String message)
        {
            log.Info(message);
        }

        public static void Error(String message)
        {
            log.Error(message);
        }

        public static void Warn(String message)
        {
            log.Warn(message);
        }

        public static void LogException(Exception ex)
        {
            log.Error("Exception=" + ex.Message + "\nStacktrace=" + ex.StackTrace);
        }

        public static void LogWarningAndError(string message, Exception ex)
        {
            log.Warn(message + ". Ex Message=" + ex.Message);
            log.Error(message + ". Ex Message=" + ex.Message + "\n          Exception Stracktrace=" + ex.StackTrace);
        }
    }
}
